package jam;

import jam.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import static org.junit.Assert.assertTrue;

/**
 * A Behavioral test that checks whether the Robots GunHeading Remains equal to it's BodyHeading
 * thought the battle.
 * 
 * @author John Mack
 * 
 */
public class TestAlignedGunHeading extends RobotTestBed {

  boolean alignedGunHeading = false;

  /**
   * Specifies that SittingDuck and RunScared are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,jam.RunScared";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * On each turn ended, check to make sure the robot's gunHeading is aligned with it's bodyHeading.
   * 
   * @param event Information about the battle.
   */

  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    checkGunHeading(robot);
  }

  /**
   * Verifies and sets boolean true if a robot's gunHeading is aligned with it's bodyHeading.
   * 
   * @param robot information about the robots gunHeading and bodyHeading
   */

  public void checkGunHeading(IRobotSnapshot robot) {
    if (robot.getGunHeading() == robot.getBodyHeading()) {
      alignedGunHeading = true;
    }

  }

  /**
   * Asserts that RunScared's GunHeading is in fact aligned with its body Heading.
   * 
   * @param event information regarding completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("The Gun is Aligned with Body", alignedGunHeading);

  }

}
